home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Singles Flirt Up Your Life! (German)
/
Singles Flirt Up Your Life.iso
/
data1.cab
/
Statemachine
/
collectDishesChar.lua
< prev
next >
Wrap
Text File
|
2004-01-29
|
8KB
|
306 lines
-- dish collecting character state machine
beginStateMachine()
onEnter(function(msg)
--local dishwasher = getStateObjectFromID(msg.sender);
local dishwasher = getStoredOrSender("dishwasher", msg)
storeStateObject("dishwasher", dishwasher);
freeHands(getParent());
end )
onExit(function(msg)
local dishwasher = retrieveStateObject("dishwasher");
if (dishwasher) then
getParent().unlockActionPoints(dishwasher);
removeStateObject("dishwasher");
end;
local table = retrieveStateObject("table");
if (table) then
print("onExit table removed");
getParent().unlockActionPoints(table);
removeStateObject("table");
else
print("onExit table NOT removed");
end
local dish = retrieveStateObject("dish");
if (dish) then
print("onExit dish removed");
removeStateObject("dish");
else
print("onExit dish NOT removed");
end
end )
state("findDishes")
onEnter(function(msg)
print("findDishes onEnter");
local table, actionPoint, dishFound = getNextTableWithDishes(getParent());
if (not table or testCancel()) then
print("no table with dishes found or cannot reach table");
if (dishFound) then
print(" --> dish was found but reachable");
-- dish was found but reachable
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
end
-- local dishHeap = getParent().getRightHeldObject();
-- if (dishHeap) then setState("gotoDishwasher"); return end;
setState("gotoDishwasher");
-- exitStateMachine();
return
end
storeStateObject("table", table);
storeData("actionPointName", actionPoint.getName());
if (walkToPointImmediate(actionPoint)) then
enterStateMachine("subwalk.walk");
else
print("no path found");
getParent().setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
-- local dishHeap = getParent().getRightHeldObject();
-- if (dishHeap) then setState("gotoDishwasher"); return end
setState("gotoDishwasher");
-- exitStateMachine();
return
end
end )
onReturn(function(msg)
print("dish collecting character findDishes onReturn");
setState("takePlate");
end )
state("takePlate")
onEnter(function(msg)
print("takePlate onEnter");
local table = retrieveStateObject("table");
local actionPointName = retrieveData("actionPointName");
if (table) then
-- table does exist
if (getParent().isActionPointLocked(table, actionPointName)) then
-- action point is locked
print("takePlate action point is locked");
setState("findDishes");
return
else
getParent().lockActionPoint(table, actionPointName);
end
else
-- table does not exist anymore
print("takePlate table does not exist anymore");
setState("findDishes");
return
end
local dishes = getChildrenWithBehavior(table, "dish");
local dish = dishes[1];
if (dish) then
storeStateObject("dish", dish);
startAnimation("takePlate");
sendDelayedMsgThis("grabPlate", 360);
sendDelayedMsgThis("dropPlate", 840);
else
setState("findDishes");
return
end
end )
onExit(function(msg)
local table = retrieveStateObject("table");
if (table) then
print("takePlate onExit table removed");
getParent().unlockActionPoints(table);
removeStateObject("table");
else
print("takePlate onExit table NOT removed");
end
local dish = retrieveStateObject("dish");
if (dish) then
print("takePlate onExit dish removed");
removeStateObject("dish");
else
print("takePlate onExit dish NOT removed");
end
end )
onMsg("grabPlate", function(msg)
-- local dish = retrieveStateObject("dish");
-- removeStateObject("dish");
-- dish.moveGameObject(getParent());
-- getParent().attachLeftObjectHolder(dish);
local dish = retrieveStateObject("dish");
removeStateObject("dish");
dish.deleteGameObject();
dish = getParent().loadGameObject("StandardGO","plate");
getParent().attachLeftObjectHolder(dish);
end )
onMsg("dropPlate", function(msg)
local numDishes = retrieveData("numDishes", 0);
storeData("numDishes", numDishes+1);
local dish = getParent().getLeftHeldObject();
getParent().detachLeftObjectHolder();
getParent().playSound("stackPlates");
local dishHeap = getParent().getRightHeldObject();
if (dishHeap) then
print("right hand full, delete plate");
dish.deleteGameObject();
else
print("move to right hand");
getParent().attachRightObjectHolder(dish);
getParent().handSO.setPose("rightHandHoldPlate");
end
end )
onMsg("end", function(msg)
setState("findDishes");
end )
state("gotoDishwasher")
onEnter(function(msg)
print("gotoDishwasher");
local character = getParent();
local numDishes = retrieveData("numDishes", 0);
local dishwasher = retrieveStateObject("dishwasher");
if ((numDishes < 1) and (getDish(dishwasher) < 1)) then
freeHands(getParent());
exitStateMachine();
return
end
--local actionPoint = getParent().getFreeActionPoint(dishwasher, {"load","washHands"});
local actionPoint = getParent().getClosestFreeActionPoint(getParent(), dishwasher, {"load","washHands"});
if (actionPoint) then
if (walkToPointImmediate(actionPoint)) then
enterStateMachine("subwalk.walk");
return
else
print("no path to dishwasher found");
character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", character.walkSO);
end
else
print("no load dishwasher action point found");
character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", character.walkSO);
end
freeHands(getParent());
exitStateMachine();
end )
onReturn(function(msg)
-- returned from subwalk to dishwasher/sink
-- print("dish collecting character gotoDishwasher onReturn");
-- local wsoContext = StateMachineContext();
-- wsoContext.storeData("numDishes", retrieveData("numDishes", 0));
-- queueStateMachine(retrieveData("washState"), retrieveStateObject("dishwasher"), wsoContext);
-- exitStateMachine();
setState("atDishwasher");
end )
state("atDishwasher")
onEnter(function(msg)
print("atDishwasher entering " .. retrieveData("washState"));
enterStateMachine(retrieveData("washState"));
end )
onReturn(function(msg)
-- returned from dishwasher/sink
print("dish collecting character atDishwasher onReturn");
exitStateMachine();
end )
-- state("gotoDishwasher")
--
-- onEnter(function(msg)
-- print("gotoDishwasher");
-- local character = getParent();
-- local numDishes = retrieveData("numDishes", 0);
--
-- if (numDishes < 1) then
-- freeHands(getParent());
-- exitStateMachine();
-- return
-- end
--
-- local dishwasher = retrieveStateObject("dishwasher");
-- --local actionPoint = getParent().getFreeActionPoint(dishwasher, {"load","washHands"});
-- local actionPoint = getParent().getClosestFreeActionPoint(getParent(), dishwasher, {"load","washHands"});
-- if (actionPoint) then
-- if (walkToActionPoint(actionPoint)) then
-- -- create state machine contexts
-- local wsoContext = StateMachineContext();
-- wsoContext.storeData("numDishes", numDishes);
-- queueStateMachine(retrieveData("washState"), dishwasher, wsoContext);
-- --queueStateMachine("dishwasherChar.load", dishwasher);
-- exitStateMachine();
-- return
-- else
-- print("no path to dishwasher found");
-- character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
-- sendMsg("emoThink", character.walkSO);
-- end
-- else
-- print("no load dishwasher action point found");
-- character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
-- sendMsg("emoThink", character.walkSO);
-- end
--
---- local dishHeap = getParent().getRightHeldObject();
---- if (dishHeap) then dishHeap.deleteGameObject(); end
---- getParent().detachRightObjectHolder();
-- freeHands(getParent());
-- exitStateMachine();
--
-- end )
endStateMachine()